// pages/index/index.js
import JSEncrypt from './jsencrypt.min.js'; // 或者 './utils/jsencrypt.min.js'
 
function encryptByPublicKey (rawData,publicKey) {
 
    console.log("原始文本为:", rawData);

    // 使用 JSEncrypt 进行加密
    let encrypt = new JSEncrypt();
    encrypt.setPublicKey(publicKey);
    let encrypted = encrypt.encrypt(rawData);

    if (!encrypted) {
      wx.showToast({ title: '加密失败', icon: 'none' });
      return;
    }

    console.log("rsa加密后的文本为:", encrypted);
    return encrypted;
  }

module.exports = {
    encryptByPublicKey: encryptByPublicKey 
}  
